/*
 * @features: 功能
 * @description: 说明
 * @Date: 2020-10-28 12:34:46
 * @Author: judu233(769471424@qq.com)
 * @LastEditTime: 2020-11-02 23:25:10
 * @LastEditors: judu233
 */

const { ccclass, property } = cc._decorator;

@ccclass
export default class PrintTxt extends cc.Component {
    @property(cc.Label)
    label: cc.Label = null;

    @property
    text: string = '';

    @property
    speed: number = 0.1;

    @property
    delay: number = 0.2;

    @property
    remainOrigintxt: boolean = false;

    @property
    repeatCount: number = 0;

    onEnable() {

        let originTxt = null;
        // if(this.remainOrigintxt)
        // {
        //     originTxt = this.label.string;
        // }

        if (this.label != null && this.text.length > 0) {
            let str = this.text;
            let j = 0;
            let currentTxt = "";
            let intervalCount = str.length - 1;
            if (this.repeatCount > 0) {
                intervalCount = str.length * this.repeatCount;
            }
            this.schedule(function () {
                if (originTxt == null) {
                    originTxt = this.label.string;
                }
                j = j % str.length;
                if (j == 0) {
                    currentTxt = "";
                }
                currentTxt = currentTxt + str[j];
                this.label.string = originTxt + currentTxt;

                j++;
            }, this.speed, intervalCount, this.delay);
        }


    }

    // update (dt) {}
}
